package org.cug.service.impl;

import org.cug.mapper.GraduateTrainingMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.GraduateTraining;
import org.cug.pojo.User;
import org.cug.service.GraduateTrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GraduateTrainingServiceimpl implements GraduateTrainingService {
    @Autowired
    private GraduateTrainingMapper graduateTrainingMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<GraduateTraining> list(Integer userId, Short semester) {
        User user = userMapper.getrole(userId);
        List<Integer> ids = new ArrayList<>();
        if (user.getRole().equals("1")) {
            ids.add(userId);
        } else if (user.getRole().equals("2")) {
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<GraduateTraining> graduateEdus = graduateTrainingMapper.listall(semester);
            return graduateEdus;
        }
        List<GraduateTraining> graduateEdus = graduateTrainingMapper.list(ids, semester);
        return graduateEdus;
    }

    @Override
    public void add(GraduateTraining graduateEdu) {
        graduateTrainingMapper.insert(graduateEdu);
    }

    @Override
    public void delete(Integer id) {
        graduateTrainingMapper.delete(id);
    }

    @Override
    public GraduateTraining selectid(Integer id) {
        return graduateTrainingMapper.selectid(id);
    }

    @Override
    public void alterbyid(GraduateTraining graduateEdu) {
        graduateTrainingMapper.update(graduateEdu);
    }
}
